package com.zhijiaoyun.common;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.zhijiaoyun.model.Banner;

/**
 * @author shisfish
 * @date 2017/6/6
 */
public class JSONUtils {

	public static String object2JsonString(Object object) {
		return JSON.toJSONString(object);
	}
	
	public static Object jsonString2Object(String jsonString, Class<?> c) {
		return JSON.parseObject(jsonString, c);
	}
	
	public static String list2JsonString(List<?> list) {
		return JSON.toJSONString(list);
	}
	
	public static List<?> jsonString2Array(String jsonString, Class<?> c) {
		return JSON.parseArray(jsonString, Banner.class);
	}
	
	
	public static void main(String[] args) {
		List<Banner> list = new ArrayList<>();
		Banner banner = new Banner("title", "imageUrl", null, 1, "jh");
		Banner banner1 = new Banner("title1", "imageUrl1", null, 2, "jh1");
		Banner banner2 = new Banner("title2", "imageUrl2", null, 3, "jh2");
		list.add(banner);
		list.add(banner1);
		list.add(banner2);
		System.out.println(object2JsonString(list));
		System.out.println(jsonString2Array(object2JsonString(list), Banner.class));
	}
	
}
